package cn.tedu;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入名字");
        String name=scan.nextLine();
        System.out.println("请输入工作");
        String job=scan.nextLine();
        System.out.println("请输入工资");
        int sal=scan.nextInt();

        try(Connection conn=DBUtils.getCoon()) {
            String sql ="insert into myemp values(null,?,?,?)";


            PreparedStatement ps= conn.prepareStatement(sql);
            //            替换SQL语句中的？
            ps.setString(1,name);
            ps.setString(2,job);
            ps.setInt(3,sal);

            ps.executeUpdate();
            System.out.println("保存成功！");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
